package com.zt.dev.system.dto;

import com.alibaba.fastjson.JSONArray;
import com.zt.dev.system.pojo.SystemRelation;
import com.zt.dev.system.vo.ReceiveRelationVo;
import com.zt.dev.system.vo.SystemStructureVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 30378
 */
@Component
public class TransformBeans {

    /**
     * 把 ReceiveRelationVo （接收的关系的 VO 转换成 SystemRelation）
     **/
    public SystemRelation receiveRelationVoTransformRelation(ReceiveRelationVo relationVo, int id) {
        SystemRelation systemRelation = new SystemRelation();
        BeanUtils.copyProperties(relationVo, systemRelation);
        systemRelation.setId(null);
        systemRelation.setItemId(relationVo.getId());
        systemRelation.setTid(id);
        return systemRelation;
    }

    /**
     * 把接收结构的第一个，拆解为体系结构信息对象
     * **/
    public SystemStructureVo getSysStructureRelation(JSONArray structureList) {
        JSONArray sysStructureList = new JSONArray();
        sysStructureList.add(structureList.get(0));
        List<SystemStructureVo> list = sysStructureList.toJavaList(SystemStructureVo.class);
        return list.get(0);
    }
}
